import Vue from 'vue'
import util from './utils.holdtime.js'

Vue.directive('has', {
  bind: function (el, binding) {
    let user = session.get('session_user')
    if (util.isString(binding.value)) {
      if (user.permissions.indexOf(binding.value) === -1) {
        Vue.nextTick(() => {
          el.parentNode.removeChild(el)
        })
      }
    } else if (util.isArray(binding.value)) {
      let has = false
      for (let val in binding.value) {
        if (user.permissions.indexOf(binding.value[val]) !== -1) {
          has = true
          break
        }
      }
      if (!has) {
        Vue.nextTick(() => {
          el.parentNode.removeChild(el)
        })
      }
    }
  }
})
